// showSub.cpp : implementation file
//

#include "stdafx.h"
#include "MultiMedia.h"
#include "showSub.h"
#include <string>


// showSub dialog

IMPLEMENT_DYNAMIC(showSub, CDHtmlDialog)

showSub::showSub(CWnd* pParent /*=NULL*/)
	: CDHtmlDialog(showSub::IDD, showSub::IDH, pParent)
{
 
}

showSub::~showSub()
{
}

void showSub::DoDataExchange(CDataExchange* pDX)
{
	CDHtmlDialog::DoDataExchange(pDX);
}

BOOL showSub::OnInitDialog()
{
	CDHtmlDialog::OnInitDialog();
	SetWindowLong(this->m_hWnd, GWL_EXSTYLE, GetWindowLong(this->m_hWnd,GWL_EXSTYLE) ^ WS_EX_LAYERED);
	SetLayeredWindowAttributes(RGB(0, 0, 0), 0, LWA_COLORKEY);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

BEGIN_MESSAGE_MAP(showSub, CDHtmlDialog)
	ON_WM_ERASEBKGND()
END_MESSAGE_MAP()

// showSub message handlers

bool showSub::SetTextCaption(BSTR caption, bool isBold)
{
	// TODO: Add your specialized code here and/or call the base class

	// Set text based on size of window
	CRect rc;
	this->GetClientRect(&rc);
	
	char setFontsize[33];
	itoa (rc.Height()/6, setFontsize, 10);

	std::string cap = _bstr_t(caption);

	std::string addFontsize;

	if (isBold)
	{	
		addFontsize.append("<b style = 'font-size:");
	}
	else
	{
		addFontsize.append("<span style = 'font-size:");
		
	}

	addFontsize.append(setFontsize);
	addFontsize.append("pt;'>");

	int pos = cap.find(">");
	if (pos > 0) 	
		cap.insert(pos + 1, addFontsize);

	caption =   A2BSTR(cap.c_str());

	IHTMLElement* pLinkElement = NULL;

	if (GetElement(_T("caption"), &pLinkElement) == S_OK && pLinkElement != NULL)
	{
		
		 pLinkElement->put_innerHTML(caption);
		 pLinkElement->Release();
		 return true;
	}

	return false;
}
void showSub::OnDocumentComplete(LPDISPATCH pDisp, LPCTSTR szUrl)
{
	CDHtmlDialog::OnDocumentComplete(pDisp, szUrl);

	// TODO: Add your specialized code here and/or call the base class
}

BOOL showSub::OnEraseBkgnd(CDC* pDC)
{
	// TODO: Add your message handler code here and/or call default
	CRect rect;
	GetClientRect(&rect);
	CBrush myBrush(COLOR_SHOW_VIDEO_AREA);    // dialog background color
	CBrush *pOld = pDC->SelectObject(&myBrush);
	BOOL bRes  = pDC->PatBlt(0, 0, rect.Width(), rect.Height(), PATCOPY);
	pDC->SelectObject(pOld);    // restore old brush
	return bRes;

	return CDHtmlDialog::OnEraseBkgnd(pDC);
}
void showSub::PostNcDestroy()
{
	// TODO: Add your specialized code here and/or call the base class
	//delete this;

	CDHtmlDialog::PostNcDestroy();
}
